package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 单选题质量评估实体类
 * 对应数据库表：sc_quality_assessments
 *
 * 根据B-02-03-03单选题管理子模块设计文档实现
 * 管理单选题的质量评估信息，包括评估任务、评估结果、评估历史等。
 * 支持自动质量评估、专家评审和基于使用数据的统计分析。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "sc_quality_assessments")
@Comment("单选题质量评估表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SingleChoiceQualityAssessment {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 评估唯一标识符
     */
    @NotBlank(message = "评估ID不能为空")
    @Size(max = 50, message = "评估ID长度不能超过50个字符")
    @Column(name = "assessment_id", nullable = false, length = 50, unique = true)
    private String assessmentId;

    /**
     * 关联的单选题ID
     */
    @NotBlank(message = "题目ID不能为空")
    @Column(name = "question_id", nullable = false)
    private String questionId;

    /**
     * 评估类型（AUTO-自动评估，EXPERT-专家评审，STATISTIC-统计分析）
     */
    @NotBlank(message = "评估类型不能为空")
    @Size(max = 20, message = "评估类型长度不能超过20个字符")
    @Column(name = "assessment_type", nullable = false, length = 20)
    private String assessmentType;

    /**
     * 评估状态（PENDING-待评估，IN_PROGRESS-评估中，COMPLETED-已完成，FAILED-评估失败）
     */
    @NotBlank(message = "评估状态不能为空")
    @Size(max = 20, message = "评估状态长度不能超过20个字符")
    @Column(name = "assessment_status", nullable = false, length = 20)
    private String assessmentStatus;

    /**
     * 评估者ID（自动评估时为系统ID）
     */
    @Column(name = "assessor_id")
    private Long assessorId;

    /**
     * 评估者姓名
     */
    @Size(max = 50, message = "评估者姓名长度不能超过50个字符")
    @Column(name = "assessor_name", length = 50)
    private String assessorName;

    /**
     * 总体质量评分（0-5分）
     */
    @Min(value = 0, message = "质量评分不能为负数")
    @Max(value = 5, message = "质量评分不能超过5分")
    @Column(name = "overall_quality_score", precision = 3, scale = 2)
    private Float overallQualityScore;

    /**
     * 内容质量评分（0-5分）
     */
    @Min(value = 0, message = "内容质量评分不能为负数")
    @Max(value = 5, message = "内容质量评分不能超过5分")
    @Column(name = "content_quality_score", precision = 3, scale = 2)
    private Float contentQualityScore;

    /**
     * 选项质量评分（0-5分）
     */
    @Min(value = 0, message = "选项质量评分不能为负数")
    @Max(value = 5, message = "选项质量评分不能超过5分")
    @Column(name = "option_quality_score", precision = 3, scale = 2)
    private Float optionQualityScore;

    /**
     * 难度适应性评分（0-5分）
     */
    @Min(value = 0, message = "难度适应性评分不能为负数")
    @Max(value = 5, message = "难度适应性评分不能超过5分")
    @Column(name = "difficulty_appropriateness_score", precision = 3, scale = 2)
    private Float difficultyAppropriatenessScore;

    /**
     * 评估结果详情（JSON格式）
     */
    @Column(name = "assessment_result", columnDefinition = "TEXT")
    private String assessmentResult;

    /**
     * 评估建议
     */
    @Column(name = "assessment_suggestion", columnDefinition = "TEXT")
    private String assessmentSuggestion;

    /**
     * 评估算法版本
     */
    @Size(max = 20, message = "评估算法版本长度不能超过20个字符")
    @Column(name = "assessment_algorithm_version", length = 20)
    private String assessmentAlgorithmVersion;

    /**
     * 评估开始时间
     */
    @Column(name = "assessment_start_time")
    private LocalDateTime assessmentStartTime;

    /**
     * 评估完成时间
     */
    @Column(name = "assessment_end_time")
    private LocalDateTime assessmentEndTime;

    /**
     * 评估耗时（毫秒）
     */
    @Min(value = 0, message = "评估耗时不能为负数")
    @Column(name = "assessment_duration_ms")
    private Long assessmentDurationMs;

    /**
     * 评估权重（用于综合评估）
     */
    @Min(value = 0, message = "评估权重不能为负数")
    @Max(value = 1, message = "评估权重不能超过1")
    @Column(name = "assessment_weight", precision = 3, scale = 2)
    private Float assessmentWeight;

    /**
     * 软删除标识
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 创建人
     */
    @Size(max = 50, message = "创建人长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

    /**
     * 更新时间
     */
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;
}